//
//  RoundInfoViewController.m
//  LiveEducation
//
//  Created by Liu,Qingcan on 2017/4/20.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import "RoundInfoViewController.h"



@interface RoundInfoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonnull,nonatomic,strong)UITableView *myTableView;

@property (nonatomic,assign)CGRect vFrame;

//@property (nonatomic,strong)NSMutableArray <RoundInfoItem *> * infoArray;

//@property (nonatomic,strong)RoundInfoItem *infoItem;
@property (nonatomic,strong) LERoomItem*roomItem;

@property (nonatomic,strong)NSArray *featureArray;
@end

@implementation RoundInfoViewController
//@synthesize infoItem = _infoItem;





+ (instancetype)initWithSubframe:(CGRect)frame roomItem:(LERoomItem *)room{
    return [[self alloc] initWithSubframe:(CGRect)frame roomItem:room];
}

- (instancetype)initWithSubframe:(CGRect)frame roomItem:(LERoomItem *)room{
    self = [super init];
    if (self) {
        
        self.vFrame = frame;
        self.roomItem = room;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubViews];
    
//    RoundInfoItem *item = [RoundInfoItem new];
//    item.features = [NSArray arrayWithObjects:@"可视化",@"高效性",@"快速性",@"真实性", nil];
//    item.learnDirection = @"滑动解锁dj";
//    item.validTime = @"38492-3489324";
//    item.sampleInfo = @"几哦几ovi哦弄";
//    item.suitable = @"老少皆宜";
//    [self setRoomItem:item];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}


#pragma UITableViewDatasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 1){
        return self.roomItem.feature.count; //self.featureArray.count;
    }else{
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *iden = @"roundInfoCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden ];
        if (cell==nil) {
            
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
        }
    
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.textLabel.font = [UIFont systemFontOfSize:12.f];
    
        if (indexPath.section == 0) { //简介
            cell.textLabel.text = self.roomItem.title;
        }else if(indexPath.section == 1){//特点
            cell.textLabel.text = self.roomItem.feature[indexPath.row];
            cell.textLabel.font = [UIFont italicSystemFontOfSize:15.2f];
            cell.textLabel.textColor = [UIColor orangeColor];
            cell.textLabel.textAlignment = NSTextAlignmentCenter;
            
        }else if (indexPath.section == 2){//价格
            cell.textLabel.text = self.roomItem.price;
        }else if(indexPath.section == 3){ //学习目标
            cell.textLabel.text = self.roomItem.classhour;
        }else if (indexPath.section == 4) {//有效时间
            cell.textLabel.text = self.roomItem.validtime;
            cell.textLabel.font = [UIFont systemFontOfSize:12.f];
            cell.textLabel.textAlignment = NSTextAlignmentCenter;
            cell.textLabel.textColor = [UIColor greenColor];
        }
    
    
    
//    RoundTableViewCell*  cell = [RoundTableViewCell cellWithRoundItem:self.roundArray[indexPath.row] tableView:tableView delegate:self];
    //        cell = (RoundTableViewCell *)[[RoundTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
    //        self.roundCell = cell;
    //        self.roundCell.mDelegate = self;
    //        self.roundCell.roundItem = self.roundArray[indexPath.row];
    
    
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 46;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return @"简介";
            break;
        case 1:
            return @"特点";
            break;
        case 2:
            return @"价格";
            break;
        case 3:
            return @"学习目标";
            break;
        case 4:
            return @"有效时间";
            break;
            
        default:
            break;
    }
    return @"";
}



#pragma RoundCellDelegate
- (void)watchButtonSelected:(NSString *)url{
    NSLog(@"watch Button!! %@",url);
    UIViewController *watchVC = [UIViewController new];
    watchVC.view.backgroundColor = [UIColor whiteColor];
    
    [self.navigationController pushViewController:watchVC animated:YES];
}


#pragma private

- (void)setupSubViews{
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.myTableView];
    
}





#pragma getter

- (UITableView *)myTableView{
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:self.vFrame];
        
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        
        _myTableView.bounces = NO;
        _myTableView.alwaysBounceVertical = YES;
        [_myTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
        _myTableView.backgroundColor = [UIColor whiteColor];
        _myTableView.showsVerticalScrollIndicator = YES;
        _myTableView.showsHorizontalScrollIndicator = NO;
        
//        [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"roundInfoCell"];
//        _myTableView.contentInset = UIEdgeInsetsMake(5, 3, 3, 3);
        
    }
    return _myTableView;
}

#pragma mark setter
//- (void)setInfoItem:(RoundInfoItem *)infoItem{
//    if (!infoItem) {
//        return;
//    }
//    _infoItem = infoItem;
//    self.featureArray = infoItem.features;
//}



//- (NSMutableArray <RoundInfoItem *>*)infoArray{
//    if (!_infoArray) {
//        _infoArray = [NSMutableArray array];
//        for (int i = 0; i < 10; i++) {
//            RoundInfoItem *item = [[RoundInfoItem alloc]init];
////            item.roundClass = [NSString stringWithFormat:@"第%d讲",i+1];
////            item.roundUrl = @"www.baidu.com";
////            item.roundName = @"欢迎来到 lqc 直播平台";
////            item.roundTime = [NSString stringWithFormat:@"2017-06-0%d",i];
//            
//            [_roundArray addObject:item];
//            
//        }
//    }
//    return _roundArray;
//}


@end
